package com.xbongbong.rule.symbol;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.rule.symbol.base.AbstractSymbol;
import com.xbongbong.saas.constant.StringConstant;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Objects;

/**
 * 同时包含判断
 * 适用类型:复选/下拉复选/关联数据多选/成员多选/部门多选/关联业务多选/子表单
 *
 * @author zheng.li
 **/
public class AllIncludeSymbol extends AbstractSymbol {

    @Override
    public boolean operation() {

        JSONArray arrayValue = factJson.getJSONArray(attr);
        if (CollectionsUtil.isNotEmpty(arrayValue)) {
            if ((attr.contains(FieldTypeEnum.SUB_FORM.getEsalias()))) {
                //子表单
                for (Object array : arrayValue) {
                    JSONArray subArray = (JSONArray) array;
                    if (CollectionsUtil.isNotEmpty(subArray) && Objects.equals(CollectionUtils.intersection(subArray, conditionValueList).size(), conditionValueList.size())) {
                        return true;
                    }
                }
            } else {
                //其他
                return Objects.equals(CollectionUtils.intersection(arrayValue, conditionValueList).size(), conditionValueList.size());
            }
        }

        return false;
    }

}
